package com.ims.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ims.common.annotation.Log;
import com.ims.common.core.controller.BaseController;
import com.ims.common.core.domain.AjaxResult;
import com.ims.common.enums.BusinessType;
import com.ims.system.domain.TSysCustomer;
import com.ims.system.service.ITSysCustomerService;
import com.ims.common.utils.poi.ExcelUtil;
import com.ims.common.core.page.TableDataInfo;

/**
 * 系统客户Controller
 *
 * @author IMS
 * @date 2024-05-25
 */
@RestController
@RequestMapping("/system/customer")
public class TSysCustomerController extends BaseController
{
    @Autowired
    private ITSysCustomerService tSysCustomerService;

    /**
     * 查询系统客户列表
     */
    @PreAuthorize("@ss.hasPermi('system:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSysCustomer tSysCustomer)
    {
        startPage();
        List<TSysCustomer> list = tSysCustomerService.selectTSysCustomerList(tSysCustomer);
        return getDataTable(list);
    }

    /**
     * 导出系统客户列表
     */
    @PreAuthorize("@ss.hasPermi('system:customer:export')")
    @Log(title = "系统客户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSysCustomer tSysCustomer)
    {
        List<TSysCustomer> list = tSysCustomerService.selectTSysCustomerList(tSysCustomer);
        ExcelUtil<TSysCustomer> util = new ExcelUtil<TSysCustomer>(TSysCustomer.class);
        util.exportExcel(response, list, "系统客户数据");
    }

    /**
     * 获取系统客户详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:customer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tSysCustomerService.selectTSysCustomerById(id));
    }

    /**
     * 新增系统客户
     */
    @PreAuthorize("@ss.hasPermi('system:customer:add')")
    @Log(title = "系统客户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSysCustomer tSysCustomer)
    {
        return toAjax(tSysCustomerService.insertTSysCustomer(tSysCustomer));
    }

    /**
     * 修改系统客户
     */
    @PreAuthorize("@ss.hasPermi('system:customer:edit')")
    @Log(title = "系统客户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSysCustomer tSysCustomer)
    {
        return toAjax(tSysCustomerService.updateTSysCustomer(tSysCustomer));
    }

    /**
     * 删除系统客户
     */
    @PreAuthorize("@ss.hasPermi('system:customer:remove')")
    @Log(title = "系统客户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tSysCustomerService.deleteTSysCustomerByIds(ids));
    }
}
